#version 460 core

layout (location = 0) out vec4 radiance;

in vec3 FragPos;
in vec2 TexCoord;
in vec3 Normal;
in vec3 Tangent;
in vec3 Bitangent;

layout(binding = 0) uniform sampler2D diffuse_map;
layout(binding = 1) uniform sampler2D normal_map;

void main()
{
	int light_n = 2;
	vec3 light_dir[2] = {normalize(vec3(1.0, 1.0, 1.0)), normalize(vec3(-1.0, -1.0, -1.0))};
	vec3 light_color[2] = {vec3(1, 1, 1), vec3(0.8, 0.8, 0.8)};
	vec3 lighting = vec3(0, 0, 0);
	for (int i = 0; i < light_n; i++)
	{
		vec3 normal_ts = texture(normal_map, TexCoord).xyz * 2 - 1;
		vec3 normal = normalize(normal_ts.x * Tangent + normal_ts.y * Bitangent + normal_ts.z * Normal);
		// lighting += max(dot(normal, light_dir[i]), 0.0) * light_color[i] * texture(diffuse_map, TexCoord).rgb;
		lighting += max(dot(normal, light_dir[i]), 0.0) * light_color[i];
	}

	radiance = vec4(lighting, 0);
}